/*
 * @Description: xxx描述文件内容
 * @Autor: gufuyan
 * @Date: 2021-11-12 09:34:32
 * @lastModifiedBy: gufuyan
 * @LastEditTime: 2021-11-30 09:38:59
 * @lastModifiedContent: xxx描述修改的内容
 */
import { extend } from 'umi-request';
import { notification } from 'antd';
// import reqConfig from "./reqConfig";

const request = extend({
  headers: {
    Accept: 'application/json, text/plain',
    'Content-Type': 'application/json',
  },
  timeout: 30000,
});

// 请求拦截
request.interceptors.request.use((url, options) => {
  return Promise.reject('手动拦截')
  return {
    url: url,
    options: { ...options },
  };
});

// 响应拦截
request.interceptors.response.use(async (response: any, options: any) => {

  try {
    const res = await response.json();
    const errorCode = '0';
    if (res.errorCode !== errorCode) {
      notification.error({
        message: '失败',
        description: res.errorMsg || '数据请求失败',
      });
      return Promise.reject(res);
    } else {
      return res;
    }
  } catch (err) {

    notification.error({
      message: '失败',
      description: '服务请求失败',
    });
    return Promise.reject(err);
  }
});

export default request;
